-
Notifications
You must be signed in to change notification settings - Fork 910
Adding functionality to config preferred authschemeProvider #6083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
362e5f3
to
f18fcc2
Compare
|
@@ -1,27 +1,15 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason we are removing copyright?
return new QueryAuthSchemeProviderBuilder(); | ||
} | ||
|
||
interface Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it extend CopyableBuilder? https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/ClientConfiguration.md
import software.amazon.awssdk.utils.Lazy; | ||
|
||
@SdkProtectedApi | ||
public class AuthSchemePreferenceProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
import software.amazon.awssdk.utils.Lazy; | ||
|
||
@SdkProtectedApi | ||
public class AuthSchemePreferenceProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests for this class? Example: https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/checksums/RequestChecksumCalculationResolverTest.java
try { | ||
client.multiAuthWithOnlySigv4aAndSigv4(MultiAuthWithOnlySigv4AAndSigv4Request.builder().build()); | ||
} catch (AutSchemeCapturingInterceptor.CaptureException e) { | ||
// expected | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use assertThatThrownBy
private static List<String> parseAuthSchemeList(String unformattedList) { | ||
if (unformattedList == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
unformattedList = unformattedList.replaceAll("\\s+", ""); | ||
String[] splitByTabs = unformattedList.split("\t"); | ||
String finalFormat = String.join("", splitByTabs); | ||
return Arrays.asList(finalFormat.split(",")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work?"\\s+"
should handle tab.
private static List<String> parseAuthSchemeList(String unformattedList) {
if (unformattedList == null) {
return Collections.emptyList();
}
return Arrays.asList(unformattedList.replaceAll("\\s+", "").split(","));
}
import software.amazon.awssdk.codegen.poet.PoetUtils; | ||
import software.amazon.awssdk.utils.CollectionUtils; | ||
|
||
public class PreferredAuthSchemeProviderSpec implements ClassSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add test case for this class?
b.addStatement("String candidateSchemeName = candidate.schemeId().contains(\"#\") ? " + | ||
"candidate.schemeId().split(\"#\")[1] : candidate.schemeId()"); | ||
b.addStatement("return candidateSchemeName.equals(preferredSchemeId)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why do we need to handle#
here?
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("schemeParsingCases") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we add a test name for each parameter?
return new QueryAuthSchemeProviderBuilder(); | ||
} | ||
|
||
interface Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing javadoc and NotThreadSafe
annotation`
Motivation and Context
Previously, when multiple auth schemes were available for an operation, the SDK would choose the first one defined in the service model. This PR implements the auth scheme preference configuration that allows users to specify their preferred authentication schemes in order of preference when multiple auth schemes are supported.
Example usage:
Modifications
[Modified] client builders to read and apply auth scheme preferences
[Modified] the auth scheme resolution logic to respect user preferences while maintaining backward compatibility
[Added]
AuthSchemePreferenceProvider
class to resolve auth scheme preferences from various sources:aws.authSchemePreference
)AWS_AUTH_SCHEME_PREFERENCE
)auth_scheme_preference
)[Added] code generation support through PreferredAuthSchemeProviderSpec to generate service-specific auth scheme providers
Testing
AuthSchemePreferenceProviderTest
verifies proper parsing of auth scheme preferences from different formats (spaces, tabs, etc.)PreferredAuthSchemeProviderTest
to test the reordering of auth schemes according to preferencescomprehensive test cases for preference resolution from multiple sources, verifying proper precedence:
Stubbed functional test with mock services to verify the selected auth scheme matches the expected preference in actual requests